package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Main3Activity extends AppCompatActivity {
    private boolean isLiked = false,isCollected = false;
    private int likeCount = 237; // 初始点赞数
    TextView likeCountView,collectView;
    ImageView likeIcon,commentIcon,collectIcon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        likeCountView = findViewById(R.id.like_count);
        collectView = findViewById(R.id.collect_text3);
        likeIcon = findViewById(R.id.like_btu3);
        commentIcon = findViewById(R.id.comment_btu3);
        collectIcon = findViewById(R.id.collect_btu3);

        likeIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isLiked = !isLiked;
                likeCount = isLiked ? likeCount + 1 : likeCount - 1;
                likeCountView.setText(String.valueOf(likeCount));
            }
        });
        commentIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(Main3Activity.this)
                        .setTitle("提示")
                        .setMessage("作者已关闭评论区")
                        .setNegativeButton("关闭", null)
                        .show();
            }
        });
        collectIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isCollected = !isCollected;
                String s = isCollected ? "已收藏" : "收藏";
                collectView.setText(s);
            }
        });
    }
}
